// 分页查询
function serch_bean(pageNum){
    //form表单序列化
    var all_val = $("#asdasd").serializeArray();
    var pageN = pageNum;
    $.get("/myspringboot/selectSupplierAll",{map:all_val,pageNum:pageN},function(pageInfo){
        var aaaa = "";  //将后端返回的参数转化为一个字符串
        $("#checkOne").empty();
        var result = pageInfo.data.list;
        yibu(pageInfo.data.pages,pageInfo.data.pageNum);
        for (var i = 0; i < result.length; i++) {    //循环遍历
            aaaa += "<tr><td>" + result[i].surId + "</td><td>" + result[i].surName + "</td><td>" +result[i].surCategory + "</td><td>" + result[i].surPlicense + "</td><td>" + result[i].surLicenseExpirationTime + "</td>" +
                "<td>" + result[i].surEnterpriseContact +"</td><td>" + result[i].sueBusinessContactNumber+ "</td><td>" + result[i].surBusinessScope+ "</td><td>" + result[i].surRegisteredAddress + "</td>" +
                "<td>" + result[i].surContactAddress + "</td><td>" + result[i].surPostalcode + "</td><td>" + result[i].surTotalAssets + "</td><td>" + result[i].surFax + "</td><td>" + result[i].surLegalPersonname + "</td>" +
                "<td>" + result[i].surLegalpersonIdcard + "</td><td>" + result[i].surEnterprise + "</td><td>" + result[i].surEmail + "</td><td>" + result[i].surUrl + "</td><td>" + result[i].surEnterpriseCodeNumber + "</td>" +
                "<td>" + result[i].surEnterpriseValidity + "</td><td>" + result[i].surBusinessLicense + "</td><td>" + result[i].surBusinessLicenseValidity + "</td><td>" + result[i].surEnterpriseLetter + "</td>" +
                "<td>" + result[i].surCreditNumber + "</td><td>" + result[i].surValidityOfCredit + "</td><td>" + result[i].surFixedAssets + "</td><td>" + result[i].surCompanyProfile + "</td><td>" + result[i].surBusinessLy + "</td>" +
                "<td>" + result[i].surRemarks + "</td>" +
                "<td id='"+ result+"'><button  data-toggle=\"modal\" data-target=\"#myModal\">新增</button> " +
                "|<button  data-toggle=\"modal\" data-target=\"#myModal1\" onclick='selectSupplierByID("+result[i].surId+")'>修改</button>" +
                "|<a  href='/myspringboot/deleteSupplier?surId=" +result[i].surId+"'>删除</a></td></tr>";
            $("#checkOne").append(aaaa);
            aaaa = "";
        }
    })
}
// 多条件查询
function serch_bean1(pageNum){
    //form表单序列化
    var all_val = $("#asdasd").serializeArray();
    $.get("/myspringboot/selectSupplier",all_val,function(result){
        var aaaa = "";  //将后端返回的参数转化为一个字符串
        $("#checkOne").empty();
        for (var i = 0; i < result.length; i++) {    //循环遍历
            aaaa += "<tr><td>" + result[i].surId + "</td><td>" + result[i].surName + "</td><td>" +result[i].surCategory + "</td><td>" + result[i].surPlicense + "</td><td>" + result[i].surLicenseExpirationTime + "</td>" +
                "<td>" + result[i].surEnterpriseContact +"</td><td>" + result[i].sueBusinessContactNumber+ "</td><td>" + result[i].surBusinessScope+ "</td><td>" + result[i].surRegisteredAddress + "</td>" +
                "<td>" + result[i].surContactAddress + "</td><td>" + result[i].surPostalcode + "</td><td>" + result[i].surTotalAssets + "</td><td>" + result[i].surFax + "</td><td>" + result[i].surLegalPersonname + "</td>" +
                "<td>" + result[i].surLegalpersonIdcard + "</td><td>" + result[i].surEnterprise + "</td><td>" + result[i].surEmail + "</td><td>" + result[i].surUrl + "</td><td>" + result[i].surEnterpriseCodeNumber + "</td>" +
                "<td>" + result[i].surEnterpriseValidity + "</td><td>" + result[i].surBusinessLicense + "</td><td>" + result[i].surBusinessLicenseValidity + "</td><td>" + result[i].surEnterpriseLetter + "</td>" +
                "<td>" + result[i].surCreditNumber + "</td><td>" + result[i].surValidityOfCredit + "</td><td>" + result[i].surFixedAssets + "</td><td>" + result[i].surCompanyProfile + "</td><td>" + result[i].surBusinessLy + "</td>" +
                "<td>" + result[i].surRemarks + "</td>" +
                "<td id='"+ result+"'><button  data-toggle=\"modal\" data-target=\"#myModal\">新增</button> " +
                "|<button data-toggle=\"modal\" data-target=\"#myModal1\" onclick='selectSupplierByID("+result[i].surId+")'>修改</button>" +
                "|<a  href='/myspringboot/deleteSupplier?surId=" +result[i].surId+"'>删除</a></td></tr>";
            $("#checkOne").append(aaaa);
            aaaa = "";
        }
    })
}

//添加gongguoshang
function lasupplier() {
    var supplier = $("#search_form").serializeArray();
    $.ajax({
        url:"/myspringboot/insertSupplier",
        data:supplier,
        type:"post",
        dataType:"json",
        success :function (result) {
            if(result=="SUCCESS"){
                alert("成功");
                // aa();
                //location.replace(location.href)
            }else{
                alert("删除失败")
            }
        }
    })
}

//修改
function selectSupplierByID(surId) {
    //通过截取路径的字符串 来获取到参数
    $.getJSON("/myspringboot/selectSupplierById", {surId:surId}, function (result14) {
        $("#id").val(surId);
        $("#name").val(result14.surName);
        $("#category").val(result14.surCategory);
        $("#plicense").val(result14.surPlicense);
        $("#licenseExpirationTime").val(result14.surLicenseExpirationTime);
        $("#enterpriseContact").val(result14.surEnterpriseContact);
        $("#businessContactNumber").val(result14.sueBusinessContactNumber);
        $("#businessScope").val(result14.surBusinessScope);
        $("#registeredAddress").val(result14.surRegisteredAddress);
        $("#contactAddress").val(result14.surContactAddress);
        $("#postalcode").val(result14.surPostalcode);
        $("#totalAssets").val(result14.surTotalAssets);
        $("#fax").val(result14.surFax);
        $("#legalPersonname").val(result14.surLegalPersonname);
        $("#legalpersonIdcard").val(result14.surLegalpersonIdcard);
        $("#enterprise").val(result14.surEnterprise);
        $("#email").val(result14.surEmail);
        $("#url").val(result14.surUrl);
        $("#enterpriseCodeNumber").val(result14.surEnterpriseCodeNumber);
        $("#enterpriseValidity").val(result14.surEnterpriseValidity);
        $("#businessLicense").val(result14.surBusinessLicense);
        $("#businessLicenseValidity").val(result14.surBusinessLicenseValidity);
        $("#enterpriseLetter").val(result14.surEnterpriseLetter);
        $("#creditNumber").val(result14.surCreditNumber);
        $("#validityOfCredit").val(result14.surValidityOfCredit);
        $("#fixedAssets").val(result14.surFixedAssets);
        $("#companyProfile").val(result14.surCompanyProfile);
        $("#businessLy").val(result14.surBusinessLy);
        $("#remarks").val(result14.surRemarks);
        //把id隐藏一下
    });
}surBusinessLicenseValidity
//修改方法
function xiugaisupplier(surId){
    var v = $("#xiugai3").serializeArray();
    $.ajax({
        url:"/myspringboot/updateSupplier",
        data:v,
        type:"post",
        dataType:"json",
        success :function (result) {
            // if(result=="SUCCESS"){
            //     alert("成功");
            //     aa();
            //     //location.replace(location.href)
            // }else{
            //     alert("修改失败")
            // }
        }
    })
}